package davidlauzon.activerecord.models;

import java.sql.SQLException;

import davidlauzon.activerecord.connection.SqliteAdapter;
import davidlauzon.activerecord.nodes.Database;
import davidlauzon.activerecord.nodes.Table;


public class DB extends Database
{
    /*********************************************************************************************
     * CONSTANTS
     *********************************************************************************************/
    static public final String NAME = "test.db";
    
    static public final Table PEOPLE_TABLE   = new Table("people", Person.FIELDS);
    static public final Table PRODUCTS_TABLE = new Table("products", Product.FIELDS);
    
    static public final Table[] TABLES = {
        PEOPLE_TABLE,
        PRODUCTS_TABLE
    };
    
    
    
    
    /*********************************************************************************************
     * SINGLETON PATTERN
     *********************************************************************************************/
    static private final Database __instance = new DB();
    static public Database getInstance() { return __instance; }
    
    private DB() {
        super();
        System.out.println("creating db");
        try { 
            setName( NAME );
            setTables( TABLES );
            setConnection( new SqliteAdapter(NAME) );
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    
    /*********************************************************************************************
     * PUBLIC METHODS
     *********************************************************************************************/
    
}
